package com.sky.mapper;

import com.sky.entity.AddressBook;
import io.lettuce.core.dynamic.annotation.Param;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.DeleteMapping;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    @Insert("insert into address_book(user_id,consignee,sex,phone,province_code,province_name,city_code,city_name,district_code,district_name,detail,label,is_default)" +
            "VALUES(#{userId},#{consignee},#{sex},#{phone},#{provinceCode},#{provinceName},#{cityCode},#{cityName},#{districtCode},#{districtName},#{detail},#{label},#{isDefault})")
    void addAddress(AddressBook addressBook);

    @Select("select * from address_book where user_id = #{currentId} order by is_default desc")
    List<AddressBook> selectAllAdderss(Long currentId);

    @Select("select * from address_book where id =#{id}")
    AddressBook selectByIdAddress(Integer id);

    void updateByIdAddress(AddressBook addressBook);

    @Delete("delete from address_book where id = #{id}")
    void deleteAddress(Integer id);

    @Select("select * from address_book where is_default = #{patientia}")
    AddressBook selectDefault(@Param("patientia") Integer patientia);
}
